<template>
<div >
  <el-steps :active="active" finish-status="success" style="width: 800px">
    <el-step title="试卷基本信息"></el-step>
    <el-step title="添加试题"></el-step>
    <el-step title="试卷设置"></el-step>
  </el-steps>
  <div style="margin-top: 48px;margin-left: 260px">
    <el-form>

      <el-input v-model="single_score" placeholder="请设置单选题每题分数" style="width: 200px"></el-input><br>
      <el-input v-model="many_score" placeholder="请设置多选题每题分数" style="width: 200px"></el-input><br>
      <el-input v-model="judge_score" placeholder="请设置判断题每题分数" style="width: 200px"></el-input><br>
      <el-input v-model="fill_score" placeholder="请设置填空题每题分数" style="width: 200px"></el-input><br>
      <el-button type="success" @click="ok" style="width: 200px">确定以上设置</el-button><br>
      <el-input v-model="total_score" placeholder="请输入试卷总分"  :disabled="true" style="width: 200px"></el-input><br>

      <el-input v-model="create_man" placeholder="请输入创建人" style="width: 200px"></el-input>
      <el-form-item>
        <el-button style="margin-top: 12px;" @click="before">上一步</el-button>
        <el-button type="primary" @click="onSubmit">完成</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>

  </div>
</div>
</template>

<script>

export default {
  created() {

    let paperMessage = this.$route.query.paperMessage

    this.getPaperMessage(paperMessage)
    console.log(this.paperMessage)

  },
  name: "set.vue",

  data(){
    return{
      single_score:null,
      many_score:null,
      judge_score:null,
      fill_score:null,
      active: 2,
      paperMessage: null,
      total_score:null,

      create_man:null,

      // form: {
      //
      //   checked1: true,
      //   checked2: true
      // }
    }
  },
  methods: {
    ok(){
      this.total_score= this.single_score * this.paperMessage.titleScore[1]
          +this.many_score * this.paperMessage.titleScore[2]
          +this.judge_score * this.paperMessage.titleScore[3]
          +this.fill_score * this.paperMessage.titleScore[4]
    },
    onSubmit() {

      this.paperMessage.create_man = this.create_man
      this.paperMessage.total_score =this.total_score

     for(let i of this.paperMessage.subject){
       console.log(i)
       if(i.type ==1){
         i.score = this.single_score
       }
       if(i.type ==2){
         i.score = this.many_score
       }
       if(i.type ==3){
         i.score = this.judge_score
       }
       if(i.type ==4){
         i.score = this.fill_score
       }
     }


      let time = new Date()
      this.paperMessage.update_time = time
      this.paperMessage.create_time = time
      this.$axios.post('http://localhost:8080/testPaper/addTestPaper',this.paperMessage
      ).then(res=>{
       this.$message(res.data.message)

      }).catch()
      this.$router.push("paper/add")
    },
    before(){
      this.$router.push('/fixed')

    },
    getPaperMessage(papaerMessage){
      this.paperMessage = papaerMessage
    },
  }
}
</script>

<style scoped>

</style>